﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using PH.Logic.Achievements;
using System.Threading;
using Utils;
using System.Xml;
namespace PH.WinForms.Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //PH.Logic.Achievements.MarkLogic l = new Logic.Achievements.MarkLogic();
            //textBox1.Text = "330302197708114810";
            MessageBox.Show(textBox1.Text.CheckIDNo().ToString());
        }

        private void button2_Click(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(Run)) { IsBackground = true }.Start();
        }

        private void Run()
        {
            using (Data.DBCentre db = new Data.DBCentre())
            {
                var lst = db.DataContext.Students.Where(p => p.StudentNo != "").OrderBy(p => p.ID).ToList();
                this.Invoke(new Action( delegate{
                    label2.Text = lst.Count.ToString();
                }));
                for (var i = 0; i < lst.Count; i++)
                {
                    this.Invoke(new Action(delegate
                    {
                        label1.Text = (i + 1).ToString();
                    }));
                    var stu = lst[i];
                    if (!stu.StudentNo.CheckIDNo())
                    {
                        stu.StudentNo = "";
                        db.DataContext.SaveChanges();
                    }
                }
            }
        }




        private void button4_Click(object sender, EventArgs e)
        {
            var token = "d7823c614d065e4d2209158d245ab841";
            var arr = new[] { token, "123456", "342" }.OrderBy(p => p).ToArray();
            string str = string.Join("", arr);
            var sha1 = System.Security.Cryptography.SHA1.Create();
            var data = Encoding.Default.GetBytes(str);
            var hashdata = sha1.ComputeHash(data);
            string realsignature = BitConverter.ToString(hashdata).Replace("-", "").ToLower();
            textBox2.Text = realsignature;
        }
    }
}
